package com.jyw.seed.controller;

import com.jyw.seed.domain.User;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/redis")
public class RedisController {

	private final StringRedisTemplate redisTemplate;

	public RedisController(StringRedisTemplate redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	@RequestMapping("/get")
	public ResponseEntity<?> get(@RequestParam String key){
		String value = redisTemplate.opsForValue().get(key);
		System.out.println("取值成功");
		return new ResponseEntity<>(value,HttpStatus.OK);
	}

	@RequestMapping("/set")
	public ResponseEntity<?> set(@RequestParam String key,String value){
		System.out.println("设置成功");
		redisTemplate.opsForValue().set(key,value);
		return new ResponseEntity<>(HttpStatus.OK);
	}
}
